package org.hit.burkun.umls.relation;

import org.hit.burkun.db.DBTypeConverter.DATATYPE;

public class UniformRealtionDBConfigure {
	// dump to db
	public static String[] dumpDBArray(UniformRelation br) {
		String[] res = new String[9]; // 主键不写入
		res[0] = br.getEnt1().getType().getTag();
		res[1] = br.getEnt1().getDbid();
		res[2] = br.getEnt1().getUid();
		res[3] = br.getEnt2().getType().getTag();
		res[4] = br.getEnt2().getDbid();
		res[5] = br.getEnt2().getUid();
		res[6] = br.getType().getTag();
		res[7] = br.getConfidscore() == null ? null : String.valueOf(br
				.getConfidscore());
		res[8] = br.isDirect() ? "1" : "0";
		return res;
	}

	// dump inverse rel to db
	public static String[] dumpReverseDBArray(UniformRelation br) {
		String[] res = new String[9]; // 主键不写入
		res[0] = br.getEnt2().getType().getTag();
		res[1] = br.getEnt2().getDbid();
		res[2] = br.getEnt2().getUid();
		res[3] = br.getEnt1().getType().getTag();
		res[4] = br.getEnt1().getDbid();
		res[5] = br.getEnt1().getUid();
		res[6] = br.getType().getTag();
		res[7] = br.getConfidscore() == null ? null : String.valueOf(br
				.getConfidscore());
		res[8] = br.isDirect() ? "1" : "0";
		return res;
	}

	public static DATATYPE[] getDbDataTypes() {
		int offset = 1;
		DATATYPE[] types = new DATATYPE[9 + offset];
		types[0] = DATATYPE.I;
		// types[7 + offset] = DATATYPE.D;
		types[8 + offset] = DATATYPE.I;
		return types;
	}

	public static DATATYPE[] getDbDataTypesWithoutPid() {
		DATATYPE[] types = new DATATYPE[9];
		// types[7] = DATATYPE.D;
		types[8] = DATATYPE.I;
		return types;
	}

	private static String[] fileds = new String[] { "ent1_type", "ent1_dbid",
			"ent1_umls", "ent2_type", "ent2_dbid", "ent2_umls", "rel_detials",
			"scores", "is_direct" };

	public static String[] getFields() {
		return fileds;
	}
}
